﻿using QG.JobBack.BLL.IService;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QG.JobBack.BLL.Service
{
    public class ManagerService : BaseRepository<Classifyinfo>, IManagerService
    {
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public bool UpdateStatus(Classifyinfo classifyinfo)
        {
            using (var db = new qgpingEntities())
            {
                Classifyinfo classifyinfos = db.Classifyinfo.FirstOrDefault(a => a.ClassId == classifyinfo.ClassId);
                classifyinfos.Status = classifyinfo.Status;
                return db.SaveChanges() > 0;
            }
        }
        /// <summary>
        /// 新增行业信息
        /// </summary>
        /// <returns></returns>
        public bool AddManagers(Classifyinfo classifyinfo)
        {
            classifyinfo.CreateTime = DateTime.Now;
            //代码执行完，则释放资源   声明一个实例
            using (var db = new qgpingEntities())
            {
                using (var tran = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Classifyinfo.Add(classifyinfo);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        tran.Rollback();
                        return false;
                    }
                    tran.Commit();
                }
            }
            return true;
        }
    }
}
